export function sleep(millsecond:number){
    return new Promise(resolve => setTimeout(resolve, millsecond));
}
export function throttle(func: (...args: any[]) => void, delay: number): (...args: any[]) => void {
    let lastCall: number = 0;
    return (...args: any[]) => {
        const now: number = new Date().getTime();
        if (now - lastCall >= delay) {
            func(...args);
            lastCall = now;
        }
    };
}

export function debounce(func: (...args: any[]) => void, delay: number): (...args: any[]) => void {
    let timeoutId: ReturnType<typeof setTimeout>;
    return (...args: any[]) => {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(() => func(...args), delay);
    };
}

export function formatDate(date){
    return `${date.getFullYear()}-${String(date.getMonth() + 1)
        .padStart(2, '0')}-${String(date.getDate())
        .padStart(2, '0')}`
}